define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dts/attendance/log/index' + location.search,
                    add_url: 'dts/attendance/log/add',
                    edit_url: 'dts/attendance/log/edit',
                    del_url: 'dts/attendance/log/del',
                    multi_url: 'dts/attendance/log/multi',
                    import_url: 'dts/attendance/log/import',
                    table: 'dts_attendance_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'admitName', title: __('Admin_id'), operate:'LIKE'},
                        {field: 'dept.name', title: __('Dept_id'), operate:'LIKE'},
                        {field: 'class.name', title: __('班级'), operate:'LIKE'},
                        // {field: 'recMode', title: __('RecMode'), searchList: {"1":__('RecMode 1')}, operate: false, formatter: Table.api.formatter.normal},
                        // {field: 'filePath', title: __('FilePath'), operate:false, formatter: Controller.api.formatter.thumb},
                        {field: 'showTime', title: __('Timestamp'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.date},
                        {field: 'mintime', title: __('Mimtime'), operate:false},
                        {field: 'maxtime', title: __('Maxtime'), operate:false},
                        // {field: 'type', title: __('Type'), operate:false, searchList: {"1":__('Type 1'), "2":__('Type 2')}, operate: false, formatter: Table.api.formatter.normal},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                thumb: function (value, row, index) {
                    return '<a href="' + row.filePath + '" target="_blank"><img src="' + row.filePath + '" alt="" style="max-height:30px;max-width:120px"></a>';
                },
            }
        }
    };
    return Controller;
});
